<!--
 * @Author: your name
 * @Date: 2021-07-26 10:23:43
 * @LastEditTime: 2023-11-07 15:31:00
 * @LastEditors: tzq
 * @Description: 实时定位气泡
 * @FilePath: \bdcar-net\src\views\trajectoryMonitor\realtimePosition\realtimeLocPop.vue
-->
<template>
  <div class="realtimeLocPop">
    <div class="close-btn" title="关闭" @click="closePop"></div>
    <div class="pop-top">
      <div class="left">
        <img :src="getImgSrc(PopData.imgURL)" class="car-img" />
        <div style="font-size: 14px;" :style="{ color: trackBool ? '#3388FF' : '#878787' }">
          跟踪
          <el-switch v-model="trackBool" style="--el-switch-on-color: #3388FF; --el-switch-off-color: #878787"
            @change="equipTrack" />
        </div>
      </div>
      <div class="right">
        <div class="equip-title">
          <span class="car-tag" :class="setTagClass(PopData.vehicleStatus)">
            {{ PopData.vehicleStatus }}
          </span>
          <span class="title-text overflow-text">
            {{ PopData.numberPlate + '-' }}
            <span :title="PopData.companyShortName">{{ PopData.companyShortName ?? '暂无公司' }}</span>
          </span>
        </div>
        <div class="name" style="background-color: #F4F6FE;">
          <div class="inline-name" style="width:30%;">速度</div>
          <div class="inline-name" style="width:40%;">总里程</div>
          <div class="inline-name" style="width:30%;">卫星数</div>
        </div>
        <div style="margin-bottom: 8px;padding-bottom: 4px;background-color: #F4F6FE;">
          <div class="inline-name" style="width:30%;font-weight: 600;">{{ PopData.spd }} km/h</div>
          <div class="inline-name" style="width:40%;font-weight: 600;">{{ PopData.kilometer }} km</div>
          <div class="inline-name" style="width:30%;font-weight: 600;">{{ PopData.satelliteCount }}</div>
        </div>
        <div class="item"><span style="color:#878787">定位时间：</span>{{ PopData.gpsDateTime }}</div>
        <div class="item"><span style="color:#878787">定位位置：</span>{{ PopData.location }}</div>
      </div>
    </div>
    <div class="pop-bottom">
      <div class="tool-btn" @click="parent.showCarDetail(PopData)"
        v-hasPermi="['trajectoryMonitor:realtimePosition:carDetail']">
        <svg-icon icon-class="popDetail" />详情
      </div>
      <div class="tool-btn" @click="parent.popTrackClick(PopData)"
        v-hasPermi="['trajectoryMonitor:realtimePosition:jumpToTrackManagement']">
        <svg-icon icon-class="popTrack" />轨迹
      </div>
      <div class="tool-btn" @click="parent.showVideoPage(PopData, getVideoImg(PopData.vehicleStatus))"
        :class="{ disabled: !getVideoImg(PopData.vehicleStatus) }" v-if="!!PopData.channelsNum">
        <svg-icon icon-class="popVideo" />视频
      </div>
      <div class="tool-btn" @click="parent.showCarDetail(PopData, 'orderSend')"
        v-hasPermi="['trajectoryMonitor:realtimePosition:orderSend']">
        <svg-icon icon-class="config" />指令
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { ref } from "vue"
import { ElSwitch } from 'element-plus'
import hasPermi from '../../../directive/permission/hasPermi'
import svgIcon from '../../../components/SvgIcon/index.vue'
export default {
  setup() {
    const parent: any = ref({})
    const PopData: any = ref({
      companyShortName: "天空众创",
      gpsDateTime: "2021-07-21 21:00:23",
      location: "武汉市某区某街道56号",
      kilometer: 0,
      numberPlate: "鄂A12345",
      spd: 0,
      vehicleStatus: "行驶",
      satelliteCount: 16,
      imgURL: null,
    })
    const trackBool = ref(false);
    return {
      PopData,
      parent,
      trackBool
    };
  },
  mounted() {
  },
  methods: {
    equipTrack() {
      this.parent.equipTrack(this.PopData);
    },
    getPopData(data: any, deviceNo) {
      this.PopData = JSON.parse(JSON.stringify(data));
      this.trackBool = this.PopData.deviceNo == deviceNo;
    },
    getImgSrc(src: string) {
      let _url;
      if (src) {
        //@ts-ignore
        _url = import.meta.env.VITE_APP_BASE_API + src
      } else {
        _url = new URL("@/assets/img/map/realCar.png", import.meta.url).href
        //@ts-ignore  调整默认图片，支持多种设备类型
        Object.entries(GlobalSetting.equipImg).forEach((v: any) => {
          if (v[1].includes(this.PopData.objIcon)) _url = new URL(`../../../assets/img/map/defaultPop/${v[0]}.png`, import.meta.url).href
        })
      }
      return _url
    },
    closePop() {
      this.parent.closePop();
    },
    getVideoImg(string: string) {
      return string == "行驶" || string == "停留" || string == "定位失败" || string == "熄火"
    },
    setTagClass(param: string) {
      let _hash: any = {
        '停留': 'carStop',
        '行驶': 'carDrive',
        '熄火': 'carFlameout',
        '离线': 'carCommunicationOutage',
        '定位失败': 'carFail',
      }
      return _hash[param]
    },
  },
  components: {
    ElSwitch, svgIcon
  },
  directives: {
    hasPermi
  },
};
</script>
<style scoped lang='scss'>
.realtimeLocPop {
  width: 400px;
  font-size: 14px;
  color: #1f1f1f;

  .close-btn {
    background: url("../../../assets/img/map/popClose.png") no-repeat center;
    background-size: 100% 100%;
    height: 16px;
    width: 16px;
    position: absolute;
    top: 10px;
    right: 10px;
    cursor: pointer;
  }

  .pop-top {
    font-size: 16px;
    color: #424242;
    margin-bottom: 10px;
    margin-right: 20px;
    display: flex;
    width: 100%;
    display: flex;

    .title-text {
      flex: 1;
      font-size: 16px;
      font-weight: 600;
      line-height: 24px;
    }

    .left {
      margin-right: 20px;

      .car-img {
        width: 105px;
        height: 105px;
      }
    }

    .right {
      width: calc(100% - 125px);
      font-size: 14px;

      .equip-title {
        width: 100%;
        display: flex;
      }

      .inline-name {
        display: inline-block;
        text-align: center;
      }

      .name {
        color: #878787;
        margin-top: 8px;
        padding-top: 4px;
        padding-bottom: 2px;
      }

      .item {
        margin-bottom: 6px;
      }
    }
  }

  .pop-bottom {
    width: 100%;
    display: flex;
    justify-content: flex-end;

    .tool-btn {
      border: 1px solid var(--el-color-primary-light-2);
      display: inline-flex;
      border-radius: 6px;
      cursor: pointer;
      width: 90px;
      height: 32px;
      align-items: center;
      justify-content: center;
      color: var(--el-color-primary);
      margin-left: 10px;
      box-sizing: border-box;

      .svg-icon {
        margin-right: 6px;
        font-size: 16px;
      }

      &:hover {
        background-color: var(--el-color-primary-light-2);
        color: #fff;
      }


      &:first-of-type {
        margin-left: 0;
      }

      &.disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }
  }
}
</style>